package com.gopay.common.cps.dao.aggregatepayment.impl;

import com.gopay.common.base.dao.impl.BaseReadDAOImpl;
import com.gopay.common.cps.dao.aggregatepayment.ApShopContractRelQueryDAO;
import com.gopay.common.cps.dao.aggregatepayment.ApShopInfoQueryDAO;
import com.gopay.common.domain.aggregatepayment.ApShopContractRel;
import com.gopay.common.domain.aggregatepayment.ApShopInfo;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Chenyu Li
 * @description 聚合支付关联关系查询DAO
 * @date 2018/1/2
 * Copyright (c) 2017. www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("apShopContractQueryRelDAO")
public class ApShopContractQueryRelDAOImpl extends BaseReadDAOImpl<ApShopContractRel,String> implements ApShopContractRelQueryDAO {

    /**
     * 获得关联关系
     * @author Chenyu Li
     * @date 2018/1/11
     * @params [apShopContractRel, pageNo, pageSize]
     * @return java.util.List<com.gopay.common.domain.aggregatepayment.ApShopContractRel>
     * @throws
     */
    @Override
    public List<ApShopContractRel> getInfoByPaged(ApShopContractRel apShopContractRel, int pageNo , int pageSize){

        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ApShopContractRel.class);
        if(StringUtils.isNotBlank(apShopContractRel.getCttId())){
            detachedCriteria.add(Restrictions.eq("cttId", apShopContractRel.getCttId()));
        }
        return findByCriteria(detachedCriteria,pageNo,pageSize);
    }

    /**
     * 获得关联关系
     * @author Chenyu Li
     * @date 2018/1/11
     * @params [apShopContractRel, pageNo, pageSize]
     * @return java.util.List<com.gopay.common.domain.aggregatepayment.ApShopContractRel>
     * @throws
     */
    @Override
    public List<ApShopContractRel> getInfo(ApShopContractRel apShopContractRel){

        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ApShopContractRel.class);
        if(StringUtils.isNotBlank(apShopContractRel.getCttId())){
            detachedCriteria.add(Restrictions.eq("cttId", apShopContractRel.getCttId()));
        }
        return findByCriteria(detachedCriteria);
    }


    /**
     * 获得关联关系计数
     * @author Chenyu Li
     * @date 2018/1/11
     * @params [apShopContractRel]
     * @return int
     * @throws
     */
    @Override
    public int getInfoCount(ApShopContractRel apShopContractRel){

        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ApShopInfo.class);
        if(StringUtils.isNotBlank(apShopContractRel.getCttId())){
            detachedCriteria.add(Restrictions.eq("cttId", apShopContractRel.getCttId()));
        }
        return findCountByCriteria(detachedCriteria);
    }
}
